#if 0
/*
 *@brief: 接口板软件升级程序
 *@date : 2015-04-17
 *@writer:lu-ming-liang
 *@least update:2015-04-17
 */
void update_sim3u146(unsigned char dt,unsigned char *src,int fd)
{
	static unsigned char results[300];
	static int clientfd = 0;
	unsigned char  frameidex = 1, packet_num = 0x0;
	unsigned short  record_idex = 0,datlen = 0,i = 0;
	int retval = 0;

	switch(dt){
	case 3:	
		clientfd = fd;
		memset(results,0,sizeof(results));
		memset(update_status,0xEE,sizeof(update_status));
		memset(update_frames,0,sizeof(update_frames));//default Frames not update
		memset(update_frames_stats,0x0E,sizeof(update_frames_stats));//default DFU Failed
		results[0] = 0x7e;
		results[3] = 0x06;
		memcpy(&results[4],&src[4],17);
		results[21] = 0x02;//TYPE
		results[22] = src[348];//num 
		record_idex = 0; 
		/*Download file from FTP Server */
		retval = run(&src[285],&src[316],&src[21],&src[25],&src[27],src);
		for(i = 349;i < 349 + src[348]*1;i+=1){
			results[23+record_idex] = src[i];	
			results[24+record_idex] = 0x01;	//default DFU Failed 
			memcpy(&results[25+record_idex],file_version,4);
			record_idex += 6;
			frameidex = src[i];
			update_frames[frameidex-1] = 1;
		}
		
		record_idex += 23;
		results[1] = record_idex >> 8 & 0xff;
		results[2] = record_idex & 0xff; 

		/* if download Failed,repost to webmaster,update_error*/
		if(retval == 0x01){
			goto update_error;
		}

		for(i = 0; i < MAX146; i++){
			if(update_frames[i] > 0)
			{/*if this frame's tray need to update*/
				memset(&uart0.txBuf[i][0],0,SZ_600);
				uart0.txBuf[i][0] = 0x7e;
				uart0.txBuf[i][1] = 0x00;
				uart0.txBuf[i][2] = 0x08;
				uart0.txBuf[i][3] = 0x06;
				uart0.txBuf[i][4] = 0x01;//startup
				uart0.txBuf[i][5] = 0x02;//type:interface board
				uart0.txBuf[i][6] = 0x01;//num : 1 ge
				uart0.txBuf[i][7] = i+1;//frameidex 
				uart0.txBuf[i][8] = crc8(&uart0.txBuf[i][0],8);
				uart0.txBuf[i][9] = 0x5a;
			}		
		}
		
		if(!order_tasks_to_sim3u146_board()){	
			/* check which board repost Failed ande mark this board update Failed */
			for(i = 0; i < MAX146; i++){
				if(uart0.txBuf[i][3] != 0x00){
					update_frames_stats[i] = 0x01;
					memset(&uart0.txBuf[i][0],0,SZ_600);
				}
			}	
			
			/* check whether all boards DFU Failed or not ?*/
			for(i = 0;i < MAX146;i++){
				if((update_frames[i] == 1) && update_frames_stats[i] == 0x0E){
					break;
				}
			}		
			/* Failed all boards,upload to webmaster */	
			if(i == MAX146)	
				goto update_error;
		}
		
		deviceUpdate = 0x01;
		/* send start update cmd */
	break;
	case 2:
		switch(src[4]){
		case 0x01:
			/* here,we are beginning to transfer First packet*/	
			frameidex = src[7];
			packet_num = 13;//First Packet addr
			if(update_frames[frameidex-1] > 0){
				memset(&uart0.txBuf[frameidex-1][0],0,SZ_600);
				uart0.txBuf[frameidex-1][0] = 0x7e;
				uart0.txBuf[frameidex-1][1] = 0x02;
				uart0.txBuf[frameidex-1][2] = 0x0c;
				uart0.txBuf[frameidex-1][3] = 0x06;
				uart0.txBuf[frameidex-1][4] = 0x02;//transfer data packet
				uart0.txBuf[frameidex-1][5] = 0x02;//type:interface board
				uart0.txBuf[frameidex-1][6] = 0x01;//num : 1 ge
				uart0.txBuf[frameidex-1][7] = frameidex;//frameidex 
				uart0.txBuf[frameidex-1][8] = 0x00;//pan hao(zhanweifu)
				uart0.txBuf[frameidex-1][9] = 0x01;//success || Failed
				uart0.txBuf[frameidex-1][10] = packet_num >> 8 & 0xff;//xuhao1
				uart0.txBuf[frameidex-1][11] = packet_num;//xuhao1 
				memcpy(&uart0.txBuf[frameidex-1][12],&data_packet[packet_num-1][0],512);
				uart0.txBuf[frameidex-1][524] = crc8(&uart0.txBuf[frameidex-1][0],524);
				uart0.txBuf[frameidex-1][525] = 0x5a;
			}		
		
			if(!order_tasks_to_sim3u146_board()){
				/* check which board repost Failed ande mark this board update Failed */
				for(i = 0; i < MAX146; i++){
					if(uart0.txBuf[i][3] != 0x00){
						update_frames_stats[i] = 0x01;
						memset(&uart0.txBuf[i][0],0,SZ_600);
					}
				}	
			
				/* check whether all boards DFU Failed or not ?*/
				for(i = 0;i < MAX146;i++){
					if((update_frames[i] == 1) && update_frames_stats[i] == 0x0E){
						break;
					}
				}		
				/* Failed all boards,upload to webmaster */	
				if(i == MAX146)	
					goto update_error;
			}
		break;
		case 0x02:
			/* here,we are beginning to transfer First packet*/	
			frameidex = src[7];
			packet_num = src[11];//First Packet addr
			if(packet_num  == data_packet_num){
					if(update_frames[frameidex-1] > 0){
					memset(&uart0.txBuf[frameidex-1][0],0,SZ_600);
					uart0.txBuf[frameidex-1][0] = 0x7e;
					uart0.txBuf[frameidex-1][1] = 0x00;
					uart0.txBuf[frameidex-1][2] = 0x10;
					uart0.txBuf[frameidex-1][3] = 0x06;
					uart0.txBuf[frameidex-1][4] = 0x03;//transfer data packet
					uart0.txBuf[frameidex-1][5] = 0x02;//type:interface board
					uart0.txBuf[frameidex-1][6] = 0x01;//num : 1 ge
					
					uart0.txBuf[frameidex-1][7] = frameidex;//frameidex 
					uart0.txBuf[frameidex-1][8] = 0x00;//pan hao(zhanweifu)
					uart0.txBuf[frameidex-1][9] = 0x01;//success || Failed
					uart0.txBuf[frameidex-1][10] = 0xff;//hardware version high bit
					uart0.txBuf[frameidex-1][11] = 0xff;//hardware version low bit
					uart0.txBuf[frameidex-1][12] = 0x00;//Software version high bit
					uart0.txBuf[frameidex-1][13] = 0x01;//Software version low bit 

					uart0.txBuf[frameidex-1][14] = 0xff;//xuhao1
					uart0.txBuf[frameidex-1][15] = 0xff;//xuhao1 
					uart0.txBuf[frameidex-1][16] = crc8(&uart0.txBuf[frameidex-1][0],16);
					uart0.txBuf[frameidex-1][17] = 0x5a;
				}			
			
			}else{

				if(update_frames[frameidex-1] > 0){
					memset(&uart0.txBuf[frameidex-1][0],0,SZ_600);
					uart0.txBuf[frameidex-1][0] = 0x7e;
					uart0.txBuf[frameidex-1][1] = 0x02;
					uart0.txBuf[frameidex-1][2] = 0x0c;
					uart0.txBuf[frameidex-1][3] = 0x06;
					uart0.txBuf[frameidex-1][4] = 0x02;//transfer data packet
					uart0.txBuf[frameidex-1][5] = 0x02;//type:interface board
					uart0.txBuf[frameidex-1][6] = 0x01;//num : 1 ge
					uart0.txBuf[frameidex-1][7] = frameidex;//frameidex 
					uart0.txBuf[frameidex-1][8] = 0x00;//pan hao(zhanweifu)
					uart0.txBuf[frameidex-1][9] = 0x01;//success || Failed
					uart0.txBuf[frameidex-1][10] = packet_num >> 8 & 0xff;//xuhao1
					uart0.txBuf[frameidex-1][11] = packet_num + 1;//xuhao1 
					memcpy(&uart0.txBuf[frameidex-1][12],&data_packet[packet_num][0],512);
					uart0.txBuf[frameidex-1][524] = crc8(&uart0.txBuf[frameidex-1][0],524);
					uart0.txBuf[frameidex-1][525] = 0x5a;
				}		
			}

			if(!order_tasks_to_sim3u146_board()){
				/* check which board repost Failed ande mark this board update Failed */
				for(i = 0; i < MAX146; i++){
					if(uart0.txBuf[i][3] != 0x00){
						update_frames_stats[i] = 0x01;
						memset(&uart0.txBuf[i][0],0,SZ_600);
					}
				}	
			
				/* check whether all boards DFU Failed or not ?*/
				for(i = 0;i < MAX146;i++){
					if((update_frames[i] == 1) && update_frames_stats[i] == 0x0E){
						break;
					}
				}		
				/* Failed all boards,upload to webmaster */	
				if(i == MAX146)	
					goto update_error;
			}
			
		break;
		case 0x03:
			/* restart sim3u146 boards*/
			frameidex = src[7];
			update_frames_stats[frameidex-1] = src[9];
			
			for(i = 23; i < results[2];i+= 6){
				if(results[i] == frameidex){
					results[i+1] = src[9];		
					break;
				}
			}

			update_status[frameidex-1] = 0x01;

			for(i = 0; i < MAX146; i++){
				if((update_frames[i] == 1) && update_frames_stats[i] == 0x0E){
					break;
				}
			}

			if(i == MAX146){
			/* i== 12,it means all interface boards that needed update
			 * finished*/	
				datlen = results[2];
				results[datlen] = crc8(results,datlen);
				results[datlen+1] = 0x5a;
				//here debug
			//	debug_net_printf(results,results[2]+2,60001);
				retval = send(clientfd,results,results[1]<<8|results[2]+2,0);
				if(retval == 0 || retval == -1){	
				/*socket abort*/	
				}
				close(clientfd);
				/* CLR Update Flags */
				deviceUpdate = 0x00;
			}

		break;
		}//endof switch(src[4])
	}

	return ;	

update_error:
	datlen = results[2];
	results[datlen] = crc8(results,datlen);
	results[datlen+1] = 0x5a;
	//here debug
//	debug_net_printf(results,results[2]+2,60001);
	retval = send(clientfd,results,results[1]<<8|results[2]+2,0);
	if(retval == 0 || retval == -1){	
		/*socket abort*/	
	}
	close(clientfd);
	/* CLR Update Flags */
	deviceUpdate = 0x0;
	return;
}
#endif 
